﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace The_LarX
{
    /// <summary>
    /// Class used for basic Per Pixel Lightning
    /// </summary>
    public class BasicLight : Component, ILight
    {
        public Vector3 Position
        {
            get
            {
                return Actor.Position;
            }
            set
            {
                Actor.Position = value;
            }
        }

        public Vector4 Color { get; set; }

        public float Power { get; set; }

        public Actor Actor { get; set; }

        protected Renderer renderer;
        /// <summary>
        /// The RenderType Used
        /// </summary>
        public Renderer Renderer { get; set; }
        

        public BasicLight(GameScreen Screen)
            : base(Screen)
        {
            EngineSystem.LightsInterface.Add(this);

            Actor = new Actor("Engine\\Light\\Model\\model_light");

            Actor.ComponentParent = this;
        }
        public BasicLight()
        {
            EngineSystem.LightsInterface.Add(this);

            Actor = new Actor("Engine\\Light\\Model\\model_light");

            Actor.ComponentParent = this;
        }

        public override void Update()
        {
            base.Update();
                        
            Actor.Update();
        }
        public override void Draw()
        {
            base.Draw();

            if (!Engine.PlayMode)
            {
                if (Renderer != null)
                    Renderer.SubmitActor(Actor);                
            }
        }

        public override void SerializeData()
        {
            base.SerializeData();
                                    
            Actor.SerializeData(Data);

            Data.AddData("Light.Color", this.Color);
            Data.AddData("Light.Power", this.Power);
        }
        public override void DeserializeData()
        {
            base.DeserializeData();

            Actor.DeserializeData(Data);

            this.Color = Data.GetData<Vector4>("Light.Color");
            this.Power = Data.GetData<float>("Light.Power");
        }
    }
}
